<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<script type="text/javascript">
    $(document).ready(function() {
        var fm = ["childForm", "child_container", "childFormId"];
        Page.createForm(fm);
        TempUtil.render('child_template', 'childForm', DOC);
        Page.postJSON({
            json: {
                cmd: RequestCmd.GET_SIP_CONFIG
            },
            success: function(data) {
              if(data.data.enable == "1"){
                $("input[value='1']").attr("checked",true);
                $("#trPort").show();
              }else{
                 $("#trPort").hide();
                $("input[value='0']").attr("checked",true);
              }

              $("#sipPort").val(data.data.port);
            }

        });

        $("input[name='sipSwich']").change(function(){
            if( $("input[value='1']").is(":checked")){
                 $("#trPort").show();
             }else{
                $("#trPort").hide();
             }
        })


    $("#btnSave").on("click",function(){
            var json = new Object();
            json.enable = $("input[name='sipSwich']:checked").val();
            json.port = $("#sipPort").val();
            if(json.enable == "1"){
                if($("#sipPort").val() == ""){
                     AlertUtil.alertMsg(CHECK.required.port);
                     return false;
                }
                var checkInfo = CheckUtil.checkPort($("#sipPort").val())
                if(!checkInfo.isValid){
                   AlertUtil.alertMsg(CHECK.format.port);
                   return false;
                }
                json.port = checkInfo.port;
            }
            json.cmd = RequestCmd.SET_SIP_CONFIG;
            json.method = JSONMethod.POST;
            Page.postJSON({
               json: json,
               success: function(data) {
                   if(data.success){
                       SysUtil.rebootDevice(PROMPT.tips.rebootMessage);
                   }
               }
           });
    })

    Page.setStripeTable();

    });
</script>

<div class="tab_box" id="child_container">
    <div id="childFormId">
        <script type="text/template" id="child_template">
        <!-- <form id="childForm"> -->    
            <table id="childTable" class="detail" cellspacing="0">
                <tr id="trDialMode">
                        <th><%- CHECK.required.sipSwitch %></th>
                        <td>
                            <input type="radio" name="sipSwich" value="1"><%- DOC.status.enabled %>
                            <input type="radio" name="sipSwich" value="0" checked><%- DOC.status.disabled %>
                        </td>
                    </tr>
                    <tr id="trPort" style="display:none;">
                        <th><%-  DOC.sip.port %></th>
                        <td>
                            <input type="text" name="sipPort" id="sipPort">
                        </td>
                    </tr>

                    
                    <tr id="trSave">
                    <th>&nbsp;</th>
                    <td>
                        <input type="button" id="btnSave" value="<%- btn.save %>"/>
                    </td>
                </tr>
            </table>                   
        <!-- </form> -->
        </script>
    </div>   
</div>
